<template>
  <div id="user_id">
    <div class="menu_top">
      <p class="menu_note">
        注:
        <br />1.增加的新栏目为当前栏目下一行
        <br />2.修改完的栏目一行需保存后提交审批才能生效
      </p>
      <div class="menu_add">
        <el-button size="mini" round @click="add_user">增加</el-button>
      </div>
    </div>

    <el-table :data="User_list" style="width: 100%">
      <el-table-column prop="id" label="编号" width="180"></el-table-column>
      <el-table-column prop="username" label="用户名" width="180"></el-table-column>
      <el-table-column prop="rolename" label="所属角色"></el-table-column>
      <el-table-column prop="status" label="状态" v-slot="$prop">
        <template>
          <el-button size="mini" type="success" round v-if="$prop.row.status==1">正常</el-button>
          <el-button size="mini" type="danger" round v-if="$prop.row.status==2">禁用</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" v-slot="$prop">
        <el-button size="mini" type="success" round @click="setuser_list($prop.row)">修改</el-button>
        <el-button size="mini" type="danger" round @click="deluser_list($prop.row.id)">删除</el-button>
      </el-table-column>
    </el-table>

    <el-pagination
      background
     layout="prev,pager ,next"
      :total="total"
      :page-size="page_size"
      @current-change="totals"
    ></el-pagination>

    <AddUser ref="add_user_ref" :isShow="isShow" :User_list="User_list" @reloadUser="reloadUser"></AddUser>
  </div>
</template>

<script>
import AddUser from "../views/AddUser.vue";
import { mapState, mapActions } from "vuex";
export default {
  data() {
    return {
      isShow: { flig: false },
      page: 1,
      page_size: 1
    };
  },
  created() {
    this.UserAcyions({ page: this.page, size: this.page_size });
    this.UserAcyions_list();
  },
  methods: {
    setuser_list(obj){
      this.isShow.flig =true
      this.$refs.add_user_ref.setuser_list(obj)
    },
    deluser_list(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!"
          });

          this.$http.post("/userdelete", { id }).then(res => {
            if (res.code == 200) {
              this.UserAcyions();
              this.UserAcyions_list();
            }
          });
          
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    reloadUser() {
      this.UserAcyions({ page: this.page, size: this.page_size });
      this.UserAcyions_list();
      
    },
    add_user() {
      this.isShow.flig = true;
    },
    totals(totals) {
      this.page = totals;
      this.UserAcyions({ page: this.page, size: this.page_size });
      this.UserAcyions_list();
       
    },
    ...mapActions("UserStory", ["UserAcyions", "UserAcyions_list"])
  },
  computed: {
    ...mapState({
      User_list: state => state.UserStory.User_list,
      total: state => state.UserStory.total
    })
  },
  components: {
    AddUser
  }
};
</script>

<style>
#user_id .menu_top {
  display: flex;
  justify-content: space-between;
}
#user_id .menu_note {
  font-size: 12px;
  color: #c4c4c4;
  text-align: left;
}
#user_id .menu_add > button {
  width: 80px;
  color: #ff5d3e;
  background-color: white;
  text-align: center;
}
</style>